﻿using AnQinManagermentBackendAPI.Model.DTO.CodeRule;
using AnQinManagermentBackendAPI.Model.View.CodeRule;
using AnQinManagermentBackendNet.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AnQinManagermentBackendNet.Controllers
{
    /// <summary>
    /// 编码规则表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class CodeRuleController : ControllerBase
    {
        /**
         * 编码规则业务接口
         */
        private readonly CodeRuleService _codeRuleService;

        /**
         * 构造函数注入
         */
        public CodeRuleController(CodeRuleService codeRuleService)
        {
            _codeRuleService = codeRuleService;
        }

        /// <summary>
        /// 获取编码规则列表
        /// </summary>
        /// <param name="codeRuleSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(CodeRuleView), 200)]
        public async Task<IActionResult> GetCodeRuleList([FromQuery] CodeRuleSearchDTO codeRuleSearchDTO)
        {
            var response = await _codeRuleService.GetCodeRuleList(codeRuleSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增编码规则
        /// </summary>
        /// <param name="codeRuleAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddCodeRule([FromBody] CodeRuleAddDTO codeRuleAddDTO)
        {
            var response = await _codeRuleService.AddCodeRule(codeRuleAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 编辑编码规则表
        /// </summary>
        /// <param name="codeRuleUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutCodeRule([FromBody] CodeRuleUpdateDTO codeRuleUpdateDTO)
        {
            var response = await _codeRuleService.PutCodeRule(codeRuleUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除编码规则表
        /// </summary>
        /// <param name="Id">编码规则表Id</param>
        [HttpDelete]
        public async Task<IActionResult> DeleteCodeRule([FromQuery] string Id)
        {
            var response = await _codeRuleService.DeleteCodeRule(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除编码规则表 - 批量
        /// </summary>
        /// <param name="Ids">编码规则表Id数组</param>
        [HttpPost("Multi")]
        public async Task<IActionResult> DeleteCodeRuleMulti([FromBody] List<string> Ids)
        {
            var response = await _codeRuleService.DeleteCodeRuleMulti(Ids);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 编码规则表 - 获取编码
        /// </summary>
        /// <param name="Id">编码规则表Id数组</param>
        [HttpGet("GetCode")]
        public async Task<IActionResult> GetCode([FromQuery] string Id)
        {
            var response = await _codeRuleService.GetNewCode(Id);
            return StatusCode(response.Status, response);
        }
    }
}
